﻿<template>
    <el-container>
        <el-header>
            <div class="left-panel">
                <!-- <el-button type="primary" icon="el-icon-plus"  @click="opBatchTask">批量收货</el-button> -->
            </div>
            <div class="right-panel">
                <el-button :icon="Search"   type="primary" @click="opBindData">查询</el-button>
                <el-button :icon="Search" type="info" plain @click="resetSearch">重置</el-button>
                <el-button text type="primary" @click="showCondition = !showCondition">
                    <span v-if="!showCondition">展开</span>
                    <span v-else>收起</span>
                    <vab-icon
                        class="vab-dropdown"
                        :class="{ 'vab-dropdown-active': fold }"
                        icon="arrow-up-s-line"
                    />
                </el-button>
            </div>
        </el-header>
        <el-foot v-show="showCondition">
            <vab-query-form-top-panel>
                <el-form inline label-width="49px" :model="queryForm" style="margin-top: 5px">
                    <el-form-item label="编号" label-width="100px">
                        <el-input
                            placeholder="---请输入编号---"
                            v-model="queryList.orderCode"
                            style="width: 300px"
                        />
                    </el-form-item>
                    <el-form-item label="收货单位" label-width="100px">
                        <sc-store-select
                            ref="orgselect"
                            :props="props"
                            :selectKeyValue="'storeId'"
                            v-model="queryList.store"
                            :multiple="false"
                            @fatherMethod="orgSelectProcess"
                        ></sc-store-select>
                    </el-form-item>
                    <el-form-item label="期望到货日期" label-width="100px">
                        <el-date-picker
                            style="width: 300px"
                            v-model="queryList.expectedDates"
                            type="datetimerange"
                            value-format="YYYY-MM-DD HH:mm:ss"
                            format="YYYY-MM-DD HH:mm:ss"
                            range-separator="-"
                            unlink-panels="true"
                            start-placeholder="开始时间"
                            end-placeholder="结束时间"
                            :default-time="defaultTime"
                        />
                    </el-form-item>
                    <el-form-item label="创建人" label-width="100px">
                        <el-input
                            placeholder="---请输入名称---"
                            v-model="queryList.crName"
                            style="width: 300px"
                        />
                    </el-form-item>
                    <el-form-item label="创建时间" label-width="100px">
                        <el-date-picker
                            style="width: 300px"
                            v-model="queryList.crDates"
                            type="datetimerange"
                            value-format="YYYY-MM-DD HH:mm:ss"
                            format="YYYY-MM-DD HH:mm:ss"
                            range-separator="-"
                            unlink-panels="true"
                            start-placeholder="开始时间"
                            end-placeholder="结束时间"
                            :default-time="defaultTime"
                        />
                    </el-form-item>
                    <el-form-item label="物料分类" label-width="100px">
                        <el-tree-select
                            placeholder="---请选择物料分类---"
                            v-model="queryList.materialTypeIds"
                            :props="{ label: 'label', value: 'value', children: 'children' }"
                            :data="materialTypeTree"
                            multiple
                            collapse-tags
                            collapse-tags-tooltip
                            :render-after-expand="false"
                            show-checkbox
                            style="width: 300px"
                        />
                    </el-form-item>
                    <el-form-item label="物料编码" label-width="100px">
                        <el-input
                            placeholder="---请输入名称---"
                            v-model="queryList.materialCode"
                            style="width: 300px"
                        />
                    </el-form-item>
                    <el-form-item label="物料简码" label-width="100px">
                        <el-input
                            placeholder="---请输入名称---"
                            v-model="queryList.materialSimpCode"
                            style="width: 300px"
                        />
                    </el-form-item>
                    <el-form-item label="物料名称" label-width="100px">
                        <el-input
                            placeholder="---请输入名称---"
                            v-model="queryList.materialName"
                            style="width: 300px"
                        />
                    </el-form-item>
                    <el-form-item label="类型" label-width="100px">
                        <el-select
                            placeholder="---请选择类型---"
                            v-model="queryList.orderType"
                            style="width: 300px"
                        >
                            <el-option label="---请选择---" value />
                            <el-option
                                v-for="item in optionsTaskOrderType"
                                :key="item.value"
                                :label="item.label"
                                :value="item.value"
                            />
                        </el-select>
                    </el-form-item>
                    <el-form-item label="状态" label-width="100px">
                        <el-select
                            placeholder="---请选择状态---"
                            v-model="queryList.taskStatus"
                            style="width: 300px"
                        >
                            <el-option label="---请选择---" value />
                            <el-option
                                v-for="item in optionsStatus"
                                :key="item.value"
                                :label="item.label"
                                :value="item.value"
                            />
                        </el-select>
                    </el-form-item>
                </el-form>
            </vab-query-form-top-panel>
        </el-foot>

        <el-main class="nopadding">
            <scTable
                ref="mytable"
                :queryType="'task-order/pages'"
                :data="listData"
                :queryList="queryList"
                :column="columnList"
                :orderList="OrderList"
                :sort-orders="['ascending', 'descending']"
                @selection-change="selectionChange"
                row-key="orderCode"
                key="orderCode"
                stripe
                show-summary
                remoteSummary
            >
                <el-table-column type="selection" width="50"></el-table-column>
                <el-table-column prop="orderDate" label="要货时间" width="140" sortable>
                    <template #default="scope">{{scope.row.orderDate?.slice(0,10)}}</template>
                </el-table-column>
				<el-table-column prop="orderCode" label="关联单号" width="180" sortable>
				    <template #default="scope">
				        <div v-if="scope.row.orderCode" class="el-span-text" @click="goTo(scope.row)">{{ scope.row.orderCode }}</div>
				        <div v-else>无</div>
				    </template>
				</el-table-column>
				<el-table-column prop="materialDescs" label="收货物料" width="260" sortable show-overflow-tooltip></el-table-column>
				<el-table-column prop="taskStatusDesc" label="收货状态" width="160" sortable></el-table-column>
				<el-table-column prop="qty" label="预计收货数量" width="140" sortable></el-table-column>
				 <el-table-column prop="totalAmount" label="金额" width="140" sortable></el-table-column>
                <el-table-column prop="taskOrderTypeDesc" label="类型" width="140" sortable></el-table-column>

                <el-table-column prop="storeName" label="收货单位" width="260" sortable></el-table-column>
                <!-- <el-table-column prop="expectedDate" label="期望到货时间" width="160" sortable>
                    <template #default="scope">{{scope.row.expectedDate?.slice(0,10)}}</template>
                </el-table-column> -->




                <el-table-column prop="crName" label="创建人" width="140" sortable></el-table-column>
               
                <el-table-column label="操作" fixed="right" align="right" width="230">
                    <template #default="scope">
                        <el-button-group>
                            <el-button
                                text
                                type="primary"
                                size="small"
                                v-show="scope.row.taskStatus<2"
                                @click="opTask(scope.row, scope.$index)"
                            >收货</el-button>
                        </el-button-group>
                        <el-button-group>
                            <el-button
                                text
                                type="primary"
                                size="small"
                                v-show="scope.row.taskStatus>0"
                                @click="opTaskItem(scope.row, scope.$index)"
                            >收货明细</el-button>
                        </el-button-group>
                    </template>
                </el-table-column>
            </scTable>
        </el-main>
    </el-container>

    <task-dialog
        v-if="dialogTask"
        ref="taskDialog"
        @fatherMethod="opBindData"
        @success="handleSaveSuccess"
        @closed="dialogTask = false"
    ></task-dialog>

    <task-item-dialog
        v-if="dialogTaskItem"
        ref="dialogTaskItem"
        @fatherMethod="opBindData"
        @success="handleSaveSuccess"
        @closed="dialogTaskItem = false"
    ></task-item-dialog>

    <give-detail-dialog
        v-if="dialogGiveDetail"
        ref="giveDetailDialog"
        @fatherMethod="opBindData"
        @success="handleSaveSuccess"
        @closed="dialogGiveDetail = false"
    ></give-detail-dialog>
</template>

<script>
import giveDetailDialog from "../give/order/detail";
import taskDialog from "./task";
import taskItemDialog from "./taskItem";
import publicjs from "@/api/model/publicjs";
import tool from "@/utils/tool";
import config from "@/config";
export default {
    name: "taskOrderAudit",
    components: {
        giveDetailDialog,
        taskDialog,
        taskItemDialog,
        publicjs,
    },
    data() {
        return {
            dialogGiveDetail:false,
            dialogTask: false,
            dialogTaskItem: false,
            showCondition: false,
            selectionRows: [],
            pkList: ["orderCode"],
            columnList: [],
            OrderList: { orderCode: "Asc" },
            queryList: {
                warehouseCode: "",
                warehouseName: "",
                status: "",
            },
            result: "", // 运行结果
            props1: {
                checkStrictly: true,
                emitPath: false,
            },
            props:{
                label: "storeName",
                value: "storeId",
            },
            orgCodeList: "",
            orgNameList: "",
            addState: true, //可以增加
            editState: true, //可以修改
            editBatchState: true, //可以批量修改
            deleteState: true, //可以删除
            optionsStatus: [],
            optionsTaskOrderType:[],
            materialTypeTree: [],
            defaultTime:[
                new Date(2000, 1, 1, 0, 0, 0),
                new Date(2000, 2, 1, 23, 59, 59),
            ]
        };
    },
    methods: {
        goTo(row){
            if(row.taskOrderType==0){
                // 跳转地址按要求更换
                this.$router.push({ path: '/apply/order', query: { applyOrderCode: row.orderCode} });
            }else{
                this.dialogGiveDetail = true;
                this.$nextTick(() => {
                    this.$refs.giveDetailDialog.setData({giveOrderId:row.orderId});
                    this.$refs.giveDetailDialog.open("Show");
                });
            }
		},
        //收货
        opTask(row) {
            this.dialogTask = true;
            this.$nextTick(() => {
                this.$refs.taskDialog.open("Task").setData([row]);
            });
        },
        //批量收货
        opBatchTask() {
            if(this.selectionRows.length==0){
                this.$message.error("请选择要收货的订单");
                return;
            }
            this.dialogTask = true;
            this.$nextTick(() => {
                this.$refs.taskDialog.open("Task").setData(this.selectionRows);
            });
        },
        //查看
        opTaskItem(row) {
            this.dialogTaskItem = true;
            this.$nextTick(() => {
                this.$refs.dialogTaskItem.open("Task").setData(row);
            });
        },
        //表格选择后回调事件
        selectionChange(selection) {
            this.selectionRows = selection;
        },
        //本地更新数据
        handleSaveSuccess(data, mode) {
            if (mode == "Add") {
                this.$refs.mytable.refresh();
            } else if (mode == "Edit") {
                this.$refs.mytable.refresh();
            }
        },
        async opBindData() {
            this.$refs.mytable.clearSort();
            this.$refs.mytable.getData();
        },
        resetSearch() {
            this.queryList = {};
        },
        async orgSelectProcess(rowData) {
            this.queryList.store = {...rowData};
            this.queryList.storeId = rowData.storeId;
            await this.opBindData();
        },
        async initOptions() {
            try {
                var returnValue = await this.$API.auth.PostProcessApi.post(
                    "base-dictionary/options",
                    { Codes: ["TaskOrderType","TaskStatus"] }
                );
                if (returnValue.status == 200) {
                    this.optionsStatus = returnValue.response.find(
                        (p) => p.code == "TaskStatus"
                    ).optionsDetails;
                    this.optionsTaskOrderType = returnValue.response.find(
                        (p) => p.code == "TaskOrderType"
                    ).optionsDetails;
                } else {
                    this.$message.error("操作失败:" + returnValue.msg);
                }
            } catch (error) {
                this.loading = false;
                return false;
            }

            try {
                var returnValue = await this.$API.auth.PostProcessApi.post(
                    "material-type/tree",
                    { status: 1 }
                );
                if (returnValue.status == 200) {
                    this.materialTypeTree = returnValue.response;
                } else {
                    this.$message.error("操作失败:" + returnValue.msg);
                }
            } catch (error) {
                this.loading = false;
                return false;
            }
        },
    },
    async mounted() {
        var taskOrderCode=this.$route.query.taskOrderCode; 
        if(taskOrderCode){
            this.queryList.taskOrderCode=taskOrderCode;
        }
        await this.initOptions();
        await this.opBindData();

    },
};
</script>
